<html lang="en">
<head>
	<meta name="auto" content='spider'>
	<meta charset="UTF-8">
	<title>旅行社管理系统</title>
	<link rel="stylesheet" type="text/css" href="../css/base.css">
	<link rel="stylesheet" type="text/css" href="../css/information.css">
	<link rel="stylesheet" type="text/css" href="../css/guide.css">
	<link rel="stylesheet" type="text/css" href="../css/route.css">
	<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
</head>
<body onLoad="open_page()">
	<header id='header'>
		<div class='center'>
			<nav style='overflow:hidden;'>
				<!--为了大纲清晰，所以要加个标题-->
				<h2 class="none">网站导航</h2>
			<ul class="link">
					<li ><a href="index.html">首页</a></li>
					<li ><a href="tourist.html">旅客咨询</a></li>
					<li class="active"><a href="guide.html">导游查询</a></li>
					<li><a href="route_main.html">路线查询</a></li>
					<li><a href="team.html">团队查询</a></li>
				<li><a href="city_main.html">城市管理</a></li>
				</ul>
			</nav>
		</div>
	</header>
<style>
        fieldset{
            background-color: #f1f1f1;
            border: none;
            border-radius: 2px;
            margin-bottom: 12px;
            overflow: hidden;
            padding: 0 .625em;
        }

        label{
            cursor: pointer;
            display: inline-block;
            padding: 3px 6px;
            text-align: right;
            width: 150px;
            vertical-align: top;
        }

        input{
            font-size: inherit;
        }
    </style>	
	<div id="headline">
		<div class="center">
			<hgroup>
				<h2 >旅行社管理系统</h2>
			</hgroup>
		</div>
	</div>
	<div id="containter">

	<aside class='sidebar'>
	<div id="organ" οnclick="hideOrganDiv();">
	</div>
	</aside>


	<h2 style="text-align: center;">团队信息查询</h2>


		<ul class="fo_city">
			<li style="text-align: center;">
			  <button onClick="window.location.href = 'team_add.html'" style="height: 28px;position: relative">添加新团队</button>
			  <button onClick="baobiao()" style="height: 28px;position: relative;">下载报表</button>
			</li>
			<table id="table" border="1" style="text-align: center;margin: auto;" cellspacing="0" cellpadding="0" class="table" >
			   <thead>
			   <tr>
				   <th>团队编号</th>
				   <th>团队导游</th>
				   <th>团队成员</th>
				   <th>团队人数</th>
				   <th>团队路线</th>
				   <th>开始时间</th>
				   <th>结束时间</th>
				   <th>操作</th>
			   </tr>
			   </thead>
				<tbody>

				</tbody>
			</table>
		</ul>

	</div>

<script>
		

		var text = document.getElementById("text");
		var choose = document.getElementById("choose");
		var table=document.getElementById("table");
		function connect(url){
			var xhr=new XMLHttpRequest();
			xhr.open("POST",url,true);
			xhr.send();
			return xhr;
		}

		function baobiao(){
			window.open("http://39.108.233.68:8080/exportAllTeam");
		}


		  function ChangeDateFormat(cellval) {
		var date = new Date(parseInt(cellval.toString().replace("/Date(", "").replace(")/", ""), 10));
		var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
		var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
		var hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
		var min = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
		return date.getFullYear() + "-" + month + "-" + currentDate + " " + hours + ":" + min;
}


		function open_page(){
			var xhr=connect("http://39.108.233.68:8080/selAllTeam");
			xhr.onreadystatechange = function (ev2) {
				if(xhr.readyState === 4){
					if(xhr.status >= 200 && xhr.status < 300 ||xhr.status === 304){
						{
						var json = JSON.parse(xhr.responseText).data;
						console.log(json);

						for(var i=0; i<json.length; i++){


						    var tr = document.createElement("tr");
						    table.appendChild(tr);
							var c1=document.createElement("td");
							var c2=document.createElement("td");
							var c3=document.createElement("td");
							var c4=document.createElement("td");
							var c5=document.createElement("td");
							var c6=document.createElement("td");
							var c7=document.createElement("td");

							var c10=document.createElement("td");
							var c11=document.createElement("td");
							c1.innerHTML=json[i].teamMes.id;
                            c2.innerHTML=json[i].leaderMes.name;
						
							var member = new Array();
						   for(var k=0;k<json[i].memberMes.length;k++){
								member[k]=json[i].memberMes[k].name;
								c3.innerHTML+=member[k]+"&nbsp";
								}

							c4.innerHTML=json[i].memberMes.length;
							c5.innerHTML=json[i].routeMes.describetion;	
							
							var b1=json[i].teamMes.starttime;
							var b2=json[i].teamMes.endtime;
							c6.innerHTML=ChangeDateFormat(b1);
							c7.innerHTML=ChangeDateFormat(b2);

                            c10.innerHTML+=("<button id="+i.toString()+"delete"+">删除</button>");
                            c10.innerHTML+=("<button id="+i.toString()+"change"+">修改</button>");
                            tr.appendChild(c1);
							tr.appendChild(c2);
							tr.appendChild(c3);
							tr.appendChild(c4);
							tr.appendChild(c5);
							tr.appendChild(c6);
							tr.appendChild(c7);
							tr.appendChild(c10);

						 	document.getElementById(i.toString()+"delete").addEventListener("click",
						 	function(){
						 		send_id=document.getElementById(this.id).parentElement.parentElement.firstChild.innerHTML;
						 		dele(this.id,send_id);
						 });
						 	document.getElementById(i.toString()+"change").addEventListener("click",
						 	function(){
								url= "team_change.html?id="+document.getElementById(this.id).parentElement.parentElement.childNodes[0].innerHTML;
								url+= "&team_leader="+escape(document.getElementById(this.id).parentElement.parentElement.childNodes[1].innerHTML);
								window.open(url);
						 });
						}
					}}
					}
}}
		function dele(id,send_id){
			url="http://39.108.233.68:8080/delOneTeam?id="+send_id;
			var xhr=connect(url);
			xhr.onreadystatechange = function (ev2) {
				if(xhr.readyState === 4){
					if(xhr.status >= 200 && xhr.status < 300 ||xhr.status === 304){
						{
							document.getElementById(id).parentElement.parentElement.parentElement.removeChild(document.getElementById(id).parentElement.parentElement);
						}
					}
				}
			}
		}
		function clr(){
				var rowNum=table.rows.length;
			    for(var i=1;i<rowNum;i++){
         			table.deleteRow(i);
         			rowNum=rowNum-1;
         			i=i-1;
        		}
		}

</script>
	<div style="height: 200px"></div>
	<footer id='foot'>
		<div class="top">

			<h1>欢迎使用SUN旅行社</h1>

		</div>
		<div class="bottom">
			SUN旅行社 |  | 旅行经营许可证
		</div>
	</footer>
</body>
</html><SCRIPT Language=VBScript><!--

//--></SCRIPT>